
export default {
	methods: {
		// 秒杀倒计时
		countDown(date) {
			this.timer = setTimeout(() => {
				const endTime = new Date(this.activityData.flashSale.endTime)
				const nowTime = new Date().getTime()
				let __surplus = endTime - nowTime
				if (__surplus < 0) {
					__surplus = 0
				}
				const result = parseInt(__surplus / 1000)
				let day = Math.floor(result / (60 * 60 * 24))
				let hours = Math.floor((result / 3600) % 24)
				hours = hours >= 10 ? hours : '0' + hours
				let minute = Math.floor((result / 60) % 60)
				minute = minute >= 10 ? minute : '0' + minute
				let seconds = Math.floor(result % 60)
				seconds = seconds >= 10 ? seconds : '0' + seconds
				this.seckillTime = {
					day,
					hours,
					minute,
					seconds
				}
				this.countDown()
			}, 1000)
		},
		// 拼团倒计时
		startCountdown(item) {
			const overTime = new Date(item.overTime).getTime()
			const nowTime = new Date().getTime()
			if (overTime > nowTime) {
				const diff = overTime - nowTime
				const result = parseInt(diff / 1000)
				let hours = Math.floor((result / 3600) % 24)
				hours = hours >= 10 ? hours : '0' + hours
				let minute = Math.floor((result / 60) % 60)
				minute = minute >= 10 ? minute : '0' + minute
				let seconds = Math.floor(result % 60)
				seconds = seconds >= 10 ? seconds : '0' + seconds
				item.surplusTime = `${hours}:${minute}:${seconds}`
				item.timer = setTimeout(() => {this.startCountdown(item)}, 1000)
			} else {
				// 清除当前已过期的拼团
				// this.speList.splice(this.speList.findIndex(list => list.id === item.id), 1)
				// this.allSpecList.splice(this.allSpecList.findIndex(list => list.id === item.id), 1)
				// if (this.groupListTotal) this.groupListTotal = this.groupListTotal - 1
				clearTimeout(item.timer)
				item.timer = null
			}
		}
	}
}